﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml;

namespace WindowsFormsApplication1.TellRequests
{
    public class TellManagerPS
    {

        private List<TellRequestPS> tellRequests = new List<TellRequestPS>();

        public void sendTellRequest(ServerSocketData socketPacket, string tellGuid, string fromName, string toName, string message, string itemLinksXml)
        {
            TellRequestPS tellRequest = new TellRequestPS(socketPacket);

            tellRequest.tellGuid = tellGuid;
            tellRequest.fromName = fromName;
            tellRequest.toName = toName;
            tellRequest.message = message;
            tellRequest.itemLinksXml = itemLinksXml;

            lock (tellRequests)
            {
                tellRequests.Add(tellRequest);
            }

            tellRequest.sendRequests();
        }

        public void completeRequest(TellRequestPS request)
        {
            lock (tellRequests)
            {
                tellRequests.Remove(request);
            }

            request.completeRequest();
        }

        public void processResult(ServerSocketData socketPacket, string tellGuid, string fromName, string toName, bool msgSuccess)
        {
            lock (tellRequests)
            {
                foreach (TellRequestPS tellrequest in tellRequests)
                {
                    if (tellrequest.tellGuid == tellGuid && tellrequest.fromName == fromName && tellrequest.toName == toName)
                    {
                        tellrequest.processResult(socketPacket, msgSuccess);
                        break;
                    }
                }
            }
        }

    }
}
